package com.ligong.blog.pojo.response;


import com.ligong.blog.contanst.Constants;
import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String errMsg;
    private T data;

    // 泛型要声明（只有static方法才要声明）
    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> Result fail(String errMag) {
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMag);
        return result;
    }

    public static <T> Result fail(String errMag, T data) {
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg(errMag);
        result.setData(data);
        return result;
    }
}
